package cn.cht.controller;

import cn.cht.constant.ConmmonConstant;
import cn.cht.pojo.Commodity;
import cn.hutool.json.JSON;
import cn.hutool.json.JSONUtil;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;


import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.ArrayList;

@Component
public class OrderInit {

    @Resource
    private RedisTemplate redisTemplate;

    /**
     * 项目初始化生成库存
     */
    @PostConstruct
    private void generateInventory(){
        ArrayList<String> list = new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            Commodity commodity = new Commodity();
            commodity.setName(commodity.getName()+i+"号");
            list.add(JSONUtil.toJsonStr(commodity));
        }
        redisTemplate.opsForList().leftPushAll(ConmmonConstant.COMMODITY_KEY,list);
        redisTemplate.opsForValue().set(ConmmonConstant.ORDKER_KEY,100);

    }

}
